<template>
  <div>
    <el-form class="query-table-form" @submit.native.prevent :inline="true" :model="params">
      <el-form-item>
        <el-input
          v-model="params.customer_name"
          placeholder="项目名称查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <el-input
          v-model="params.corp_name"
          placeholder="负责人查询"
          clearable
          @change="getData()"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <select-address
          v-model="params.address_code"
          clearable
          placeholder="地址查询"
          auto-top
          @change="getData()"
        ></select-address>
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" @click="getData()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          icon="el-icon-download"
          :loading="exportLoading"
          @click="exportExcel('签约放款（已拒绝）')"
        >
          导出
        </el-button>
      </el-form-item>
    </el-form>

    <c-table border v-loading="loading" :columns="tableColumns" :data="tableData">
      <template v-slot:address="scope">
        <el-tooltip effect="light" :content="scope.row.address">
          <div class="text-truncate">{{ scope.row.address }}</div>
        </el-tooltip>
      </template>

      <template v-slot:projectEleStatus="scope">
        <span class="badge" :class="`badge-${scope.row.projectEleStatusStyle}`">
          {{ scope.row.projectEleStatusLabel }}
        </span>
      </template>
    </c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      :before-close="beforeClose"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="调查报告" name="file">
          <credit-file :query-id="queryId" view-mode></credit-file>
        </el-tab-pane>
        <el-tab-pane label="政府推荐函" name="recommend" v-if="fileData.isGovSubmit">
          <recommend-file :related-data="fileData"></recommend-file>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <attach-file :customerRelatedId="attachId" :visible.sync="attachVisible"></attach-file>

    <reject-detail :visible.sync="rejectVisible" :related-data="rejectData"></reject-detail>
  </div>
</template>

<script>
import SelectAddress from '@/components/select/SelectAddress'
import CreditFile from '@/credit/components/creditFile/InvestigateReport'
import RecommendFile from '@/credit/views/city/program/RecommendFile'
import AttachFile from '@/credit/views/city/program/Attach'
import RejectDetail from '@/credit/views/city/self/RejectDetail'

import taskTableMixin from '@/credit/mixin/county/taskTable'

import { enumGuatype } from '@/credit/plugins/enumTown'
import { prelimTableColumns } from '@/credit/views/city/self/Preliming'

export default {
  components: {
    SelectAddress,
    CreditFile,
    RecommendFile,
    AttachFile,
    RejectDetail,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      enumGuatype,
      params: {
        index: 1,
        size: 10,
        customer_name: '',
        corp_name: '',
        address_code: '',
        'gua_type.eq': 1,
        'loan_notice_status.neq': 2,
        'city_project_res_status.eq': 2,
        'confuse_status.eq': 3,
      },
      order: {
        N2create_time: 'DESC',
      },
      useRegisterTable: true,
      tableColumns: [
        ...prelimTableColumns,
        { attrs: { label: '拒绝时间', prop: 'refuseTime', align: 'center', width: 140 } },
        { attrs: { label: '合作银行', prop: 'bank_name', align: 'center' } },
        { attrs: { label: '拒绝理由', prop: 'confuse_des', align: 'center' } },
        {
          attrs: { label: '操作', align: 'center', minWidth: 150 },
          operations: [
            {
              content: '拒绝详情',
              icon: 'fa fa-file-o',
              event: this.handleDetail,
            },
            {
              content: '附件',
              icon: 'fa fa-clipboard',
              event: this.handleAttach,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.hanleView,
            },
          ],
        },
      ],

      activeName: 'file',

      // 档案卡
      queryId: '',
      reportVisible: false,
      fileData: {},

      // 附件
      attachId: '',
      attachVisible: false,

      // 拒绝详情
      rejectVisible: false,
      rejectData: {},
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getData()
  },
  mounted() {},
  methods: {
    dataAdapter(item) {
      item.guaType = enumGuatype[item.gua_type] || '-'
      item.refuseTime = this.$utils.dateFormat(item.confuse_time, this.dateFmt)

      item.submitType = +item.submit_type
      item.isGovSubmit = item.submitType === 1

      return item
    },
    handleAttach(row) {
      this.attachId = row.customer_related_id
      this.attachVisible = true
    },
    handleDetail(row = {}) {
      this.rejectVisible = true
      this.rejectData = { ...row }
    },
    hanleView(row) {
      this.showFile(row)
    },
    showFile(row = {}) {
      this.fileData = row
      this.queryId = this.fileData.customer_related_id
      this.reportVisible = true
    },
    beforeClose() {
      this.reportVisible = false
      setTimeout(() => (this.activeName = 'file'), 200)
    },
  },
}
</script>
<style lang="scss" scoped></style>
